import RequestProcess from "./RequestProcess";
import OperateArgs from "../operator/OperateArgs";
import OperatorDecorator from "../operator/OperatorDecorator";
import { RC } from "../config/RC";
import GetUserOrGroupNameOperation from "../operator/GetUserOrGroupNameOperation";
import CheckNameGetOrNotOperation from "../operator/CheckNameGetOrNotOperation";


class GetNameByIdRequestProcess extends RequestProcess {

    public args_generate(): void {
        this.args = new OperateArgs();
        this.args.setProperty("Id", this.req.body.Id);
    }

    public operator_plan_generate(): void {
        const get_name_by_id = new GetUserOrGroupNameOperation(this.args);
        const check_type = new CheckNameGetOrNotOperation(this.args);

        this.operator_plan = new OperatorDecorator(get_name_by_id,check_type);
    }

    public writeResult(rc: RC): Object {
        switch (rc) {
            case RC.SUCCESS:
                return {
                    code: "0000",
                    msg: "获取成功",
                    type: this.getOperateArgs().getProperty("type"),
                    name: this.getOperateArgs().getProperty("Name")
                }
            case RC.ID_NOTEXIST:
                return {
                    code: "1010",
                    msg: "ID不存在"
                }
            case RC.INTERNAL_ERROR:
                return {
                    code: "1003",
                    msg: "服务器内部错误"
                }
            default:
                return {
                    code: "2000",
                    msg: "未知错误"
                }
        }
    }
}

export default GetNameByIdRequestProcess;